home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga News 95
/
Amiga News 95.iso
/
dpat
/
dpat05
/
castet
/
castet.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-05
|
45KB
|
1,002 lines
/**************************************************************************/
/* */
/* CasTet.c */
/* */
/* Ce programme ouvre une fenètre et dessine les */
/* pièces d'un casse-tete....................... */
/* */
/* Compilé avec Lattice 4.0 */
/* */
/**************************************************************************/
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <graphics/gfx.h>
#include <graphics/gfxmacros.h>
#include <string.h>
#include <exec/types.h>
#define RPORT Fenetre->RPort
#define LARGEUR 218
#define HAUTEUR 171
struct GfxBase *GfxBase;
extern struct IntuitionBase *IntuitionBase;
struct Window *Fenetre;
struct NewWindow NouvFenetre={
50,30,
LARGEUR,HAUTEUR,
3,1,
CLOSEWINDOW|MOUSEBUTTONS, /*flags pour action attendu */
WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|ACTIVATE|GIMMEZEROZERO|SMART_REFRESH,
0,0,
"Casse-tronche",
0,0,
0,0,
LARGEUR,HAUTEUR,
WBENCHSCREEN
};
struct IntuiMessage *Message;
UWORD ImageSignature_data[16 * 30 * 2] = {
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0x9fff,0xffff,0xffff,0xffff,0xffff,0x9fff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xff7f,0x7fff,0xffff,0xffff,0x3fff,0xffff,0xffff,0xffff,0xffff,0x3fff,0xffff,0xffff,0xfffd,0xfdff,0xffff,
0xffff,0xffbe,0xffff,0xffff,0xfffe,0x7fff,0xffff,0xffff,0xffff,0xfffe,0x7cff,0xffff,0xffff,0xfffe,0xfbff,0xffff,
0xffff,0xfedd,0xbfff,0xfffe,0x0703,0xffff,0xffff,0xfffc,0x1fff,0xffff,0xf8ff,0xffff,0xffff,0xfffb,0x76ff,0xffff,
0xfffd,0xffeb,0xffdf,0xffff,0x0fc4,0x1038,0x1c03,0xffff,0x0fe0,0x861c,0x1000,0xe01f,0xffff,0xf7ff,0xafff,0x7fff,
0xfffd,0xbf3e,0x7edf,0xffff,0x8fce,0x187c,0x38e3,0xffff,0x87f0,0x208e,0x1f8f,0xc71f,0xffff,0xf6fc,0xf9fb,0x7fff,
0xfffe,0x73aa,0xe73f,0xffff,0x8fcf,0x1c7e,0x71e3,0xffff,0x03f8,0x71c7,0x1e3f,0x8f1f,0xffff,0xf9ce,0xab9c,0xffff,
0xffff,0x29d5,0xca7f,0xffff,0x8fcf,0x1c7e,0x63e3,0xfffe,0x61f8,0xf1c7,0x1c7f,0x1f1f,0xffff,0xfca7,0x5729,0xffff,
0xffc8,0x79ff,0xcf09,0xffff,0xc79f,0x1e3c,0xe3e3,0xfff9,0xc0f8,0xf1c7,0x18ff,0x1f1f,0xffff,0x21e7,0xff3c,0x27ff,
0xfff7,0x73ff,0xe777,0xffff,0xe33f,0x1f19,0xf1e3,0xfff1,0x9878,0xf1c7,0x1c7f,0x8f1f,0xffff,0xddcf,0xff9d,0xdfff,
0xffff,0x07ff,0xf07f,0xffff,0xf07f,0x1f83,0xf8e0,0x7ff0,0x7c38,0xf1c7,0x1e3f,0xc703,0xffff,0xfc1f,0xffc1,0xffff,
0xffff,0xffff,0xffff,0xffff,0xf8ff,0x1fc7,0xfc00,0xfff9,0xfe18,0xe38f,0x1f87,0xe007,0xffff,0xffff,0xffff,0xffff,
0xffff,0x07ff,0xf07f,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfff1,0xffff,0xffff,0xfc1f,0xffc1,0xffff,
0xfff7,0x73ff,0xe777,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfe78,0xffff,0xffff,0xddcf,0xff9d,0xdfff,
0xffc8,0x3dff,0xde09,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf871,0xffff,0xffff,0x20f7,0xff78,0x27ff,
0xffff,0x6380,0xe37f,0xe007,0xffff,0xffff,0xffff,0xe007,0xffff,0xfcff,0xff03,0xf1ff,0xffff,0xfd8e,0x038d,0xffff,
0xfffe,0xff3e,0x7fbf,0xe003,0xffff,0xffff,0xffff,0xe007,0xffff,0xf87f,0xffff,0xf1ff,0xffff,0xfbfc,0xf9fe,0xffff,
0xfffd,0xbfaa,0xfedf,0xf1e1,0xffff,0xffff,0xffff,0xc7c7,0xffff,0xf87f,0xffff,0xf3ff,0xffff,0xf6fe,0xabfb,0x7fff,
0xffff,0xffc9,0xffff,0xf1e0,0x010c,0x200f,0x01ff,0x8fe6,0x0218,0x6038,0x6100,0x61e0,0x200f,0xffff,0x27ff,0xffff,
0xffff,0xfedd,0xbfff,0xf001,0x000c,0x2006,0x00ff,0xcffc,0x0018,0x7378,0x6100,0x21c0,0x0007,0xfffb,0x76ff,0xffff,
0xffff,0xff3e,0x7fff,0xf20e,0xdb8e,0x31c6,0x78ff,0x9ffc,0xf11c,0x79fc,0x7186,0x31c8,0x10c7,0xfffc,0xf9ff,0xffff,
0xffff,0xffff,0xffff,0xf5ea,0xbfce,0xbdf6,0x3eff,0xefe4,0x7d9d,0x7afe,0x75ef,0xf9c2,0x19ff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xfbf7,0xffbe,0xb7df,0xfbff,0x97df,0xf77d,0x7d8d,0xf5bf,0xf7ff,0x97ff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xe408,0x9ff1,0xceba,0xc7ff,0xd01d,0x8fe3,0xba2f,0x8e77,0xeed8,0x6eff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xf7ff,0xffff,0xfeff,0xfdff,0xf7ff,0xfbfe,0xffff,0xfbf7,0xffff,0xbfff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x6000,0x0000,0x0000,0x0000,0x0000,0x6000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0xf000,0x0000,0x0000,0x0000,0x0000,0xf000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0080,0x8000,0x0000,0x0001,0xe000,0x0000,0x0000,0x0000,0x0001,0xe300,0x0000,0x0000,0x0002,0x0200,0x0000,
0x0000,0x0041,0x0000,0x0001,0xf8ff,0xc000,0x0000,0x0003,0xe000,0x0003,0xc780,0x0000,0x0000,0x0001,0x0400,0x0000,
0x0000,0x0122,0x4000,0x0003,0xfdff,0xefc7,0xe3fc,0x0007,0xf01f,0x79e3,0xefff,0x1fe0,0x0000,0x0004,0x8900,0x0000,
0x0002,0x0014,0x0020,0x0001,0xf8ff,0xffef,0xf7fe,0x0003,0xf83f,0xfff7,0xffff,0xbff0,0x0000,0x0800,0x5000,0x8000,
0x0002,0x40c1,0x8120,0x0000,0xf87b,0xffc7,0xeffe,0x0000,0xfc1f,0xfffb,0xffff,0x7ff0,0x0000,0x0903,0x0604,0x8000,
0x0001,0x8c55,0x18c0,0x0000,0xf879,0xf7c3,0xdf3e,0x0001,0xfe0f,0xdf7d,0xf3f0,0xf9f0,0x0000,0x0631,0x5463,0x0000,
0x0000,0xd62a,0x3580,0x0000,0xf879,0xf7c3,0xfe3e,0x0007,0xff0f,0x9f7d,0xf7c1,0xf1f0,0x0000,0x0358,0xa8d6,0x0000,
0x0037,0x8600,0x30f6,0x0000,0x7cf1,0xf3e7,0xbe3e,0x000f,0xff8f,0x9f7d,0xff81,0xf1f0,0x0000,0xde18,0x00c3,0xd800,
0x0008,0x8c00,0x1888,0x0000,0x3fe1,0xf1ff,0x1f3f,0x801f,0xffcf,0x9f7d,0xf7c0,0xf9fc,0x0000,0x2230,0x0062,0x2000,
0x0000,0xf800,0x0f80,0x0000,0x1fc1,0xf0fe,0x0fff,0xc01f,0xe7ef,0x9f7d,0xf3f8,0x7ffe,0x0000,0x03e0,0x003e,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0f81,0xf07c,0x07ff,0x800f,0x83ff,0xbef9,0xf1fe,0x3ffc,0x0000,0x0000,0x0000,0x0000,
0x0000,0xf800,0x0f80,0x0000,0x0700,0xe038,0x03ff,0x0006,0x01e7,0x1c70,0xe1ff,0x1ff8,0x0000,0x03e0,0x003e,0x0000,
0x0008,0x8c00,0x1888,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07cf,0x8000,0x0000,0x2230,0x0062,0x2000,
0x0037,0xc200,0x21f6,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0fff,0x0000,0x0000,0xdf08,0x0087,0xd800,
0x0000,0x9c7f,0x1c80,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x07fe,0x0000,0x0000,0x0271,0xfc72,0x0000,
0x0001,0x00c1,0x8040,0x1ff8,0x0000,0x0000,0x0000,0x1ff8,0x0000,0x0300,0x00fc,0x0e00,0x0000,0x0403,0x0601,0x0000,
0x0002,0x4055,0x0120,0x0e1c,0x0000,0x0000,0x0000,0x3838,0x0000,0x0700,0x0000,0x0e00,0x0000,0x0901,0x5404,0x8000,
0x0000,0x0036,0x0000,0x0e1c,0x0000,0x0000,0x0000,0x7018,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0xd800,0x0000,
0x0000,0x0122,0x4000,0x0e1f,0xfef3,0xdff0,0xfe00,0x7001,0xfde7,0x9fc7,0x9eff,0x9e1f,0xdff0,0x0004,0x8900,0x0000,
0x0000,0x00c1,0x8000,0x0ff9,0xe771,0xce39,0xc700,0x7003,0x8ee3,0x8703,0x8e79,0xce38,0xef38,0x0003,0x0600,0x0000,
0x0000,0x0000,0x0000,0x0e1d,0xc071,0xce39,0xc700,0x7003,0x8ee3,0x8703,0x8e70,0x0e3f,0xee00,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0e1d,0xc071,0xce39,0xc700,0x701b,0x8ee3,0x8703,0x8e70,0x0e38,0x0e00,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0e1d,0xc071,0xce39,0xc700,0x3833,0x8ee3,0x8773,0x8e70,0x0e38,0x6e00,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x1ffb,0xe03f,0x7f7c,0xfe00,0x1fe1,0xfc7f,0xc3e1,0xfff8,0x1f1f,0xdf00,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
struct Image ImageSignature = {
0, 0, 256, 30, 2, &ImageSignature_data[0], 3, 0, NULL};
/*********************************************** */
/* Pointer Data */
/*************************************************/
/* Pointeur fer a cheval */
#define POINTER1_HEIGHT 16
#define POINTER1_WIDTH 16
#define POINTER1_HOTX -9
#define POINTER1_HOTY 0
UWORD pointer1_dat[] = {
0x0000,0x0000,
0x0,0x5225,
0x0,0x294A,
0x0,0x140,
0x0,0x1C1C,
0x0,0x1C1C,
0x1C1C,0x404,
0x1C1C,0x404,
0x1C1C,0x404,
0x380E,0x802,
0x380E,0x802,
0x380E,0x802,
0x380E,0x802,
0x1C1C,0x404,
0x1FF8,0x3C0,
0xFF0,0x0,
0x3C0,0x0,
0x0000,0x0000
};
int TableauJeu[6][7]={
{20,20,20,20,20,20,20},
{20, 1, 1, 2, 2, 6,20},
{20, 0, 0, 5, 7,10,20},
{20, 0, 0, 5, 8,10,20},
{20, 3, 3, 4, 4, 9,20},
{20,20,20,20,20,20,20}
};
int TabPiece[10][4]={
{2,1,2,2},
{1,1,1,2},
{1,3,1,2},
{4,1,1,2},
{4,3,1,2},
{2,3,2,1},
{1,5,1,1},
{2,4,1,1},
{3,4,1,1},
{4,5,1,1}
};
int PosX,PosY;
long TaH,TaV;
long int coup;
long DeplN=0,DeplS=0,DeplO=0,DeplE=0;
long Etat=-1;
long im=0;
char ascoup[4];
#define MAXITEMS 5
struct Menu Menus;
struct MenuItem Items[5];
struct MenuItem SubItem[4];
struct IntuiText Texts[5];
struct IntuiText SubTexts[4];
char *IString[9]={
"COUPS N° 0","How to play","Info"," ",
"Wait and see...",
"COUTURIER Bruno le 01 01 1990",
"Reset","Quit",
"Observez l'icone / Look at the Icon"};
VOID OpenAll();
VOID CloseIt();
VOID Dessin();
VOID DetectMess();
VOID DeterPos();
VOID IDCMPoff();
VOID IDCMPon();
VOID Dessine();
long Verif();
VOID BuildUpMenu();
VOID Compte();
VOID Reset();
/******************************************************************************/
/* */
/* Prg principal */
/* */
/******************************************************************************/
void _main()
{
long v=0;
OpenAll();
Reset();
while(v!=2)
{
DetectMess();
v=Verif();
if(v>0)
{
SetAPen(RPORT,0);
RectFill(RPORT,0,0,218,171);
SetAPen(RPORT,2);
RectFill(RPORT,0,0,218,171);
SetAPen(RPORT,3);
Move(RPORT,30,71);
Draw(RPORT,181,71);
Move(RPORT,30,78);
SetDrMd(RPORT,JAM2|INVERSVID);
Text(RPORT,"Bravo :",7);
Text(RPORT,Texts[0].IText,12);
Wait(1<<Fenetre->UserPort->mp_SigBit);
v=0;
Reset();
}
}
}
/******************************************************************************/
/* */
/* Cette fonction ouvre les librairies et la fenetre et construit le menu */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucun */
/* */
/******************************************************************************/
VOID OpenAll()
{
IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0);
if (!IntuitionBase)CloseIt();
GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0);
if (!GfxBase)CloseIt();
Fenetre=(struct Window *)OpenWindow(&NouvFenetre);
if (!Fenetre)CloseIt();
BuildUpMenu();
SetMenuStrip(Fenetre,&Menus);
SetPointer(Fenetre,&pointer1_dat[0],POINTER1_HEIGHT,POINTER1_WIDTH,
POINTER1_HOTX,POINTER1_HOTY);
}
/******************************************************************************/
/* */
/* Cette routine ferme tout */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :chaine à sortir */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID CloseIt()
{
if(Fenetre)ClearPointer(Fenetre);
if(Fenetre)ClearMenuStrip(Fenetre);
if(Fenetre)CloseWindow(Fenetre);
if(GfxBase)CloseLibrary(GfxBase);
if(IntuitionBase)CloseLibrary(IntuitionBase);
exit(0);
}
/******************************************************************************/
/* */
/* Cette routine dessine la position initiale */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID Dessin()
{
register i;
BNDRYOFF(RPORT);
SetDrMd(RPORT,JAM1);
SetAPen(RPORT,0);
RectFill(RPORT,0,0,218,171);
TaH=TabPiece[0][2];
TaV=TabPiece[0][3];
Dessine(TabPiece[0][0],TabPiece[0][1],3);
for(i=1;i<=9;i++)
{
TaH=TabPiece[i][2];
TaV=TabPiece[i][3];
Dessine(TabPiece[i][0],TabPiece[i][1],2);
}
}
/******************************************************************************/
/* */
/* Cette routine determine PosX et PosY en fonction de MouseX et MouseY */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :MX= MouseX */
/* MY= MouseY */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID DeterPos(MX,MY)
register MX,MY;
{
if(MX>0)
{
if((MX>213)&&(MX<3))PosX=-1;
if((MX>160)&&(MX<=213))PosX=4;
if((MX<=160)&&(MX>110))PosX=3;
if((MX>53)&&(MX<=110))PosX=2;
if(MX<=53)PosX=1;
}
if(MX<=0)PosX=-1;
if(MY>0)
{
if((MY>170)&&(MY<=10))PosY=-1;
if((MY<=169)&&(MY>137))PosY=5;
if((MY<=137)&&(MY>105))PosY=4;
if((MY<=105)&&(MY>73))PosY=3;
if((MY<=73)&&(MY>41))PosY=2;
if(MY<=41)PosY=1;
}
if(MY<=0)PosY=-1;
}
/******************************************************************************/
/* */
/* Cette fonction désactive le transfert de messages */
/* par Intuition.C'est très important car les messages */
/* d'Intuition sont normalement sauvegardé dans une */
/* list(queue),pour ètre traités l'un après l'autre. */
/* Comme il est cependant impossible,par moments, de */
/* réagir à Intuition(par exemple pendant le calcul ou */
/* le dessin),il faut éviter que des messages envoyés */
/* pendant ce temps(par exemple des touches actionnées) */
/* ne s'accumulent pour ètre ensuite traités de façon */
/* assez incohérente (pour l'utilisateur). */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée : aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse : aucune */
/* */
/******************************************************************************/
VOID IDCMPoff()
{
SetMenuStrip(Fenetre,NULL);
ModifyIDCMP(Fenetre,NULL); /* Eliminer le menu de la fenetre */
}
/******************************************************************************/
/* */
/* Cette routine autorise à nouveau Intuition à envoyer des messages. */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée : aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse : aucune */
/* */
/******************************************************************************/
VOID IDCMPon()
{
SetMenuStrip(Fenetre,&Menus);
ModifyIDCMP(Fenetre,MOUSEBUTTONS|CLOSEWINDOW|MENUPICK);
}
/******************************************************************************/
/* */
/* Cette routine detecte un message d'Intuition */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID DetectMess()
{
long Class,Code;
long x,y,Piece,PosXact,PosYact;
IDCMPon();
Wait(1<<Fenetre->UserPort->mp_SigBit);
while(Message=(struct IntuiMessage *)GetMsg(Fenetre->UserPort))
{
im=0;
Class=Message->Class;
Code=Message->Code;
x=Message->MouseX;
y=Message->MouseY;
ReplyMsg(Message);
switch(Class)
{
case MOUSEBUTTONS:
if((Code==SELECTDOWN)&(Etat==-1))
{
IDCMPoff();
DeterPos(x,y);
if((PosX>-1)&&(PosY>-1))
{
Piece=TableauJeu[PosX][PosY];
if(Piece!=10)
{
PosXact=TabPiece[Piece][0];
PosYact=TabPiece[Piece][1];
TaH=TabPiece[Piece][2];
TaV=TabPiece[Piece][3];
DeplN=DeplS=DeplO=DeplE=0;
if((TableauJeu[PosXact-1][PosYact]==10)&
(TableauJeu[PosXact-1][PosYact+TaV-1]==10))DeplO=1;
if((TableauJeu[PosXact][PosYact-1]==10)&
(TableauJeu[PosXact+TaH-1][PosYact-1]==10))DeplN=1;
if((TableauJeu[PosXact+TaH][PosYact]==10)&
(TableauJeu[PosXact+TaH][PosYact+TaV-1]==10))DeplE=1;
if((TableauJeu[PosXact][PosYact+TaV]==10)&
(TableauJeu[PosXact+TaH-1][PosYact+TaV]==10))DeplS=1;
if((DeplN==1)|(DeplO==1)|(DeplE==1)|(DeplS==1))
{
SetOPen(RPORT,1);
if(Piece==0)Dessine(PosXact,PosYact,2);
if(Piece!=0)Dessine(PosXact,PosYact,3);
Etat=Piece;
im=1;
}
}
}
}
if((Code==SELECTDOWN)&(Etat!=-1)&(im==0))
{
IDCMPoff();
DeterPos(x,y);
if((PosX>-1)&&(PosY>-1))
{
Piece=TableauJeu[PosX][PosY];
if(Piece==Etat)
{
BNDRYOFF (RPORT);
if(Piece==0)Dessine(PosXact,PosYact,3);
if(Piece!=0)Dessine(PosXact,PosYact,2);
Etat=-1;
}
if(Piece==10)
{
if((PosX==PosXact-1)&
((PosY==PosYact)|(PosY==PosYact+TaV-1))&(DeplO==1))
{
TableauJeu[PosXact-1][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact-1][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][0]-=1;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact-1,PosYact,3);
if(Etat!=0)Dessine(PosXact-1,PosYact,2);
Compte();
Etat=-1;
}
if((PosX==PosXact-2)&
((PosY==PosYact)|(PosY==PosYact+TaV-1))&(DeplO==1))
{
TableauJeu[PosXact-2][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact-2][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact-2+TaH-1][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact-2+TaH-1][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact]=10;
TableauJeu[PosXact][PosYact+TaV-1]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][0]-=2;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact-2,PosYact,3);
if(Etat!=0)Dessine(PosXact-2,PosYact,2);
Compte();
Compte();
Etat=-1;
}
if((PosX==PosXact+TaH)&
((PosY==PosYact)|(PosY==PosYact+TaV-1))&(DeplE==1))
{
TableauJeu[PosXact+TaH][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact+TaV-1];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact][PosYact+TaV-1]=10;
TabPiece[Etat][0]+=1;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact+1,PosYact,3);
if(Etat!=0)Dessine(PosXact+1,PosYact,2);
Compte();
Etat=-1;
}
if((PosX==PosXact+TaH+1)&
((PosY==PosYact)|(PosY==PosYact+TaV-1))&(DeplE==1))
{
TableauJeu[PosXact+TaH+1][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH+1][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact+TaV-1];
TableauJeu[PosXact+TaH+1-(TaH-1)][PosYact]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH+1-(TaH-1)][PosYact+TaV-1]=
TableauJeu[PosXact][PosYact+TaV-1];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact][PosYact+TaV-1]=10;
TableauJeu[PosXact+TaH-1][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][0]+=2;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact+2,PosYact,3);
if(Etat!=0)Dessine(PosXact+2,PosYact,2);
Compte();
Compte();
Etat=-1;
}
if(((PosX==PosXact)|(PosX==PosXact+TaH-1))&
(PosY==PosYact-2)&(DeplN==1))
{
TableauJeu[PosXact][PosYact-2]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact-2]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact][PosYact-2+(TaV-1)]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact-2+(TaV-1)]=
TableauJeu[PosXact+TaH-1][PosYact];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact]=10;
TableauJeu[PosXact][PosYact+TaV-1]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][1]-=2;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact,PosYact-2,3);
if(Etat!=0)Dessine(PosXact,PosYact-2,2);
Compte();
Compte();
Etat=-1;
}
if(((PosX==PosXact)|(PosX==PosXact+TaH-1))&
(PosY==PosYact-1)&(DeplN==1))
{
TableauJeu[PosXact][PosYact-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact-1]=
TableauJeu[PosXact+TaH-1][PosYact];
TableauJeu[PosXact][PosYact+TaV-1]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][1]-=1;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact,PosYact-1,3);
if(Etat!=0)Dessine(PosXact,PosYact-1,2);
Compte();
Etat=-1;
}
if(((PosX==PosXact)|(PosX==PosXact+TaH-1))&
(PosY==PosYact+TaV)&(DeplS==1))
{
TableauJeu[PosXact][PosYact+TaV]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact+TaV]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact]=10;
TabPiece[Etat][1]+=1;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact,PosYact+1,3);
if(Etat!=0)Dessine(PosXact,PosYact+1,2);
Compte();
Etat=-1;
}
if(((PosX==PosXact)|(PosX==PosXact+TaH-1))&
(PosY==PosYact+TaV+1)&(DeplS==1))
{
TableauJeu[PosXact][PosYact+2]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact+2]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact][PosYact+2+TaV-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact+TaH-1][PosYact+2+TaV-1]=
TableauJeu[PosXact][PosYact];
TableauJeu[PosXact][PosYact]=10;
TableauJeu[PosXact+TaH-1][PosYact]=10;
TableauJeu[PosXact][PosYact+TaV-1]=10;
TableauJeu[PosXact+TaH-1][PosYact+TaV-1]=10;
TabPiece[Etat][1]+=2;
BNDRYOFF(RPORT);
Dessine(PosXact,PosYact,0);
if(Etat==0)Dessine(PosXact,PosYact+2,3);
if(Etat!=0)Dessine(PosXact,PosYact+2,2);
Compte();
Compte();
Etat=-1;
}
}
}
}
IDCMPon();
break;
case MENUPICK:
if(Code!=MENUNULL)
switch(MENUNUM(Code))
{
case 0:
switch(ITEMNUM(Code))
{
case 4:
switch(SUBNUM(Code))
{
case 0:
IDCMPoff();
Reset();
IDCMPon();
break;
case 1:
CloseIt();
}
}
}
break;
case CLOSEWINDOW:
CloseIt();
}
}
}
/******************************************************************************/
/* */
/* Cette routine verifie si la position est gagnante */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :v=1 si position gagnante */
/* */
/******************************************************************************/
long Verif()
{
register long v=0;
if(TableauJeu[2][5]==TableauJeu[3][5]==10)v=1;
return(v);
}
/******************************************************************************/
/* */
/* Cette routine dessine une piece */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :x=PosXact de la piece */
/* y=PosYact de la piece */
/* Apen= couleur */
/* */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID Dessine(x,y,Apen)
register x,y,Apen;
{
long x1,y1,x2,y2;
SetAPen(RPORT,Apen);
x1=(x-1)*(50+3);
y1=(y-1)*(30+2);
x2=(x-1)*(50+3)+(TaH*50)+((TaH-1)*3);
y2=(y-1)*(30+2)+(TaV*30)+((TaV-1)*2);
RectFill(RPORT,x1,y1,x2,y2);
}
/******************************************************************************/
/* */
/* Cette fonction construit un menu et ses entrées */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* Rques:il faut définir MAXITEMS, BuilDUpMenu(),struct Menu Menus, */
/* struct MenuItem Items,struct IntuiText Texts,char *IString... */
/* dans le prg */
/* */
/******************************************************************************/
VOID BuildUpMenu()
{
long i;
Items[0].LeftEdge=1; /* Item 1 */
Items[0].TopEdge=0;
Items[0].Width=120; Items[0].Height=10;
Items[0].Flags=ITEMTEXT|ITEMENABLED|HIGHNONE;
Items[0].MutualExclude=NULL;
Items[0].ItemFill=(APTR)&Texts[0];
Items[0].SelectFill=NULL;
Items[0].Command=NULL;
Items[0].SubItem=NULL;
Items[0].NextSelect=NULL;
Texts[0].FrontPen=3; Texts[0].BackPen=1;
Texts[0].DrawMode=JAM1;
Texts[0].LeftEdge=1; Texts[0].TopEdge=1;
Texts[0].ITextFont=NULL;
Texts[0].IText=IString[0];
Texts[0].NextText=NULL;
Items[1].LeftEdge=1; /* Item 2 */
Items[1].TopEdge=10;
Items[1].Width=120; Items[1].Height=10;
Items[1].Flags=ITEMTEXT|ITEMENABLED|HIGHCOMP;
Items[1].MutualExclude=NULL;
Items[1].ItemFill=(APTR)&Texts[1];
Items[1].SelectFill=NULL;
Items[1].Command=NULL;
Items[1].SubItem=&SubItem[0];
Items[1].NextSelect=NULL;
Texts[1].FrontPen=3; Texts[1].BackPen=1;
Texts[1].DrawMode=JAM1;
Texts[1].LeftEdge=1; Texts[1].TopEdge=1;
Texts[1].ITextFont=NULL;
Texts[1].IText=IString[1];
Texts[1].NextText=NULL;
Items[2].LeftEdge=1; /* Item 3 */
Items[2].TopEdge=20;
Items[2].Width=120; Items[2].Height=10;
Items[2].Flags=ITEMTEXT|ITEMENABLED|HIGHCOMP;
Items[2].MutualExclude=NULL;
Items[2].ItemFill=(APTR)&Texts[2];
Items[2].SelectFill=NULL;
Items[2].Command=NULL;
Items[2].SubItem=&SubItem[1];
Items[2].NextSelect=NULL;
Texts[2].FrontPen=3; Texts[2].BackPen=1;
Texts[2].DrawMode=JAM1;
Texts[2].LeftEdge=1; Texts[2].TopEdge=1;
Texts[2].ITextFont=NULL;
Texts[2].IText=IString[2];
Texts[2].NextText=NULL;
Items[3].LeftEdge=1; /* Item 4 */
Items[3].TopEdge=30;
Items[3].Width=120; Items[3].Height=10;
Items[3].Flags=ITEMTEXT;
Items[3].MutualExclude=NULL;
Items[3].ItemFill=(APTR)&Texts[3];
Items[3].SelectFill=NULL;
Items[3].Command=NULL;
Items[3].SubItem=NULL;
Items[3].NextSelect=NULL;
Texts[3].FrontPen=3; Texts[3].BackPen=1;
Texts[3].DrawMode=JAM1;
Texts[3].LeftEdge=1; Texts[3].TopEdge=1;
Texts[3].ITextFont=NULL;
Texts[3].IText=IString[3];
Texts[3].NextText=NULL;
Items[4].LeftEdge=1; /* Item 5 */
Items[4].TopEdge=40;
Items[4].Width=120; Items[4].Height=10;
Items[4].Flags=ITEMTEXT|ITEMENABLED|HIGHBOX;
Items[4].MutualExclude=NULL;
Items[4].ItemFill=(APTR)&Texts[4];
Items[4].SelectFill=NULL;
Items[4].Command=NULL;
Items[4].SubItem=&SubItem[2];
Items[4].NextSelect=NULL;
Texts[4].FrontPen=3; Texts[4].BackPen=1;
Texts[4].DrawMode=JAM1;
Texts[4].LeftEdge=1; Texts[4].TopEdge=1;
Texts[4].ITextFont=NULL;
Texts[4].IText=IString[4];
Texts[4].NextText=NULL;
SubItem[0].NextItem=NULL;
SubItem[0].LeftEdge=120; /* SubItem 1 */
SubItem[0].TopEdge=0;
SubItem[0].Width=200; SubItem[0].Height=10;
SubItem[0].Flags=ITEMTEXT|ITEMENABLED|HIGHNONE;
SubItem[0].MutualExclude=NULL;
SubItem[0].ItemFill=(APTR)&SubTexts[0];
SubItem[0].SelectFill=NULL;
SubItem[0].Command=NULL;
SubItem[0].SubItem=NULL;
SubItem[0].NextSelect=NULL;
SubTexts[0].FrontPen=3; SubTexts[0].BackPen=1;
SubTexts[0].DrawMode=JAM1;
SubTexts[0].LeftEdge=1; SubTexts[0].TopEdge=1;
SubTexts[0].ITextFont=NULL;
SubTexts[0].IText=IString[8];
SubTexts[0].NextText=NULL;
SubItem[1].NextItem=NULL;
SubItem[1].LeftEdge=120; /* SubItem 2 */
SubItem[1].TopEdge=0;
SubItem[1].Width=256; SubItem[1].Height=30;
SubItem[1].Flags=ITEMENABLED|HIGHCOMP;
SubItem[1].MutualExclude=NULL;
SubItem[1].ItemFill=(APTR)&ImageSignature;
SubItem[1].SelectFill=NULL;
SubItem[1].Command=NULL;
SubItem[1].SubItem=NULL;
SubItem[1].NextSelect=NULL;
SubItem[2].NextItem=&SubItem[3];
SubItem[2].LeftEdge=120; /* SubItem 3 */
SubItem[2].TopEdge=0;
SubItem[2].Width=44; SubItem[2].Height=10;
SubItem[2].Flags=ITEMTEXT|ITEMENABLED|HIGHCOMP;
SubItem[2].MutualExclude=NULL;
SubItem[2].ItemFill=(APTR)&SubTexts[2];
SubItem[2].SelectFill=NULL;
SubItem[2].Command=NULL;
SubItem[2].SubItem=NULL;
SubItem[2].NextSelect=NULL;
SubTexts[2].FrontPen=3; SubTexts[2].BackPen=1;
SubTexts[2].DrawMode=JAM1;
SubTexts[2].LeftEdge=1; SubTexts[2].TopEdge=1;
SubTexts[2].ITextFont=NULL;
SubTexts[2].IText=IString[6];
SubTexts[2].NextText=NULL;
SubItem[3].NextItem=NULL;
SubItem[3].LeftEdge=120; /* SubItem 4 */
SubItem[3].TopEdge=10;
SubItem[3].Width=44; SubItem[3].Height=10;
SubItem[3].Flags=ITEMTEXT|ITEMENABLED|HIGHCOMP;
SubItem[3].MutualExclude=NULL;
SubItem[3].ItemFill=(APTR)&SubTexts[3];
SubItem[3].SelectFill=NULL;
SubItem[3].Command=NULL;
SubItem[3].SubItem=NULL;
SubItem[3].NextSelect=NULL;
SubTexts[3].FrontPen=3; SubTexts[3].BackPen=1;
SubTexts[3].DrawMode=JAM1;
SubTexts[3].LeftEdge=1; SubTexts[3].TopEdge=1;
SubTexts[3].ITextFont=NULL;
SubTexts[3].IText=IString[7];
SubTexts[3].NextText=NULL;
for(i=0;i<MAXITEMS-1;i++)
Items[i].NextItem=&Items[i+1];
Items[MAXITEMS-1].NextItem=NULL;
Menus.NextMenu=NULL;
Menus.LeftEdge=0; Menus.TopEdge=0;
Menus.Width=63; Menus.Height=10;
Menus.Flags=MENUENABLED;
Menus.MenuName="Projets";
Menus.FirstItem=&Items[0];
}
/******************************************************************************/
/* */
/* Cette routine compte et modifie le menu */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID Compte()
{
char *p;
register i;
coup++;
if(coup==10000)coup=0;
p=stpcpy(Texts[0].IText,"COUP N° ");
stci_d(ascoup,coup);
for(i=0;i<4-strlen(ascoup);++i)
p=stpcpy(p," ");
p=stpcpy(p,ascoup);
}
/******************************************************************************/
/* */
/* Cette fonction initialise le tableau de jeu et toute le variables */
/* */
/*----------------------------------------------------------------------------*/
/* Parametres en entrée :aucun */
/*----------------------------------------------------------------------------*/
/* Valeurs de réponse :aucune */
/* */
/******************************************************************************/
VOID Reset()
{
char *p;
TableauJeu[1][1]=TableauJeu[1][2]=1;
TableauJeu[1][3]=TableauJeu[1][4]=2;
TableauJeu[1][5]=6;
TableauJeu[2][1]=TableauJeu[2][2]=0;
TableauJeu[2][3]=5;
TableauJeu[2][4]=7;
TableauJeu[2][5]=10;
TableauJeu[3][1]=TableauJeu[3][2]=0;
TableauJeu[3][3]=5;
TableauJeu[3][4]=8;
TableauJeu[3][5]=10;
TableauJeu[4][1]=TableauJeu[4][2]=3;
TableauJeu[4][3]=TableauJeu[4][4]=4;
TableauJeu[4][5]=9;
TabPiece[0][0]=2;
TabPiece[0][1]=TabPiece[1][0]=TabPiece[1][1]=TabPiece[2][0]=1;
TabPiece[2][1]=3;
TabPiece[3][0]=4;
TabPiece[3][1]=1;
TabPiece[4][0]=4;
TabPiece[4][1]=3;
TabPiece[5][0]=2;
TabPiece[5][1]=3;
TabPiece[6][0]=1;
TabPiece[6][1]=5;
TabPiece[7][0]=2;
TabPiece[7][1]=4;
TabPiece[8][0]=3;
TabPiece[8][1]=4;
TabPiece[9][0]=4;
TabPiece[9][1]=5;
DeplN=DeplS=DeplO=DeplS=im=0;
Etat=-1;
coup=0;
p=stpcpy(Texts[0].IText,"COUP N° 0");
Dessin();
}